package rullekake.facade;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import rullekake.entities.Course;
import rullekake.entities.Faculty;

/**
 * Utvider AbstractFacade for Course.
 * Tar seg av peristence for Course-objekter
 * 
 */
@Stateless
public class CourseFacade extends AbstractFacade<Course> {
    @PersistenceContext(unitName = "SystemeringPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public CourseFacade() {
        super(Course.class);
    }

    /**
     * Finner alle emner som er med i gitt fakultet
     * @param faculty
     * @return liste med emner
     */

    public List<Course> findCoursesByFaculty(Faculty faculty) {
        javax.persistence.Query q = getEntityManager().createNamedQuery("Course.findByFaculty");
        q.setParameter("faculty", faculty);
        return q.getResultList();
    }
}
